﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace WQDSkin.Forms.Component
{
    public class FormHelp
    {
        public static bool Verifiy(DependencyObject reference)
        {
            return VerifiyChildren(reference);
        }

        private static bool VerifiyChildren(DependencyObject reference)
        {

            int count = VisualTreeHelper.GetChildrenCount(reference);
            for (int i = 0; i < count; i++)
            {
                DependencyObject child = VisualTreeHelper.GetChild(reference, i);
                if (child is IForm)
                {
                    IForm form = (IForm)child;
                    if (form.Required) //如果是必须项
                    {
                        bool verifiy = form.Verifiy();
                        if (!verifiy) //如果失败直接返回
                        {
                            return false;
                        }
                    }
                }
                else
                {
                    if (child is ContentControl || child is TextBlock)
                    {
                        continue;
                    }
                    else
                    {
                        return VerifiyChildren(child);
                    }

                }
            }
            return true;
        }
    }
}
